package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: TaskTagServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_task_tag
 * Comment:
 * 任务标签表
 */
@Service
public class TaskTagServiceImpl extends TaskTagServiceCustomImpl implements TaskTagService {

    static {
        beanClassNameMap.put("task_tag", "taskTagServiceImpl");
        listMethodNameMap.put("task_tag", "listTaskTag");
        listMethodParameterClassNameMap.put("task_tag", "TaskTagQueryRequest");
        updateMethodNameMap.put("task_tag", "updateTaskTag");
        updateMethodParameterClassNameMap.put("task_tag", "TaskTagUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addTaskTag(TaskTagAddRequest request) throws Exception {
        super.fixRequest("task_tag", "add", request);
        return super.addTaskTag(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateTaskTag(TaskTagUpdateRequest request) throws Exception {
        TaskTag record = null;
        record = taskTagMapper.selectByPrimaryKey(request.getId());
        super.fixRequest("task_tag", "update", request, record);
        return super.updateTaskTag(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteTaskTag(TaskTagDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<TaskTag> list = null;
            TaskTagExample example = new TaskTagExample();
            example.createCriteria().andIdIn(request.getIdList());
            list = taskTagMapper.selectByExample(example);
            fixRequest("task_tag", "delete", request, list);
        } else {
            fixRequest("task_tag", "delete", request);
        }
        return super.deleteTaskTag(request);
    }

    @Override
    public TaskTagQueryResponse queryTaskTag(TaskTagQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "id");
        TaskTagQueryResponse result = super.queryTaskTag(request);
        checkResult("task_tag", "query", request, result);
        return result;
    }

    @Override
    public List<TaskTagQueryResponse> listTaskTag(TaskTagQueryRequest request) throws Exception {
        List<TaskTagQueryResponse> list = super.listTaskTag(request);
        checkResult("task_tag", "list", request, list);
        return list;
    }

    @Override
    public Integer countTaskTag(TaskTagQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_tag", "count", request);
        return super.countTaskTag(request);
    }

    @Override
    public BaseStatResponse statTaskTag(TaskTagQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_tag", "stat", request);
        return super.statTaskTag(request);
    }

    @Override
    public List<TaskTagForTagsResponse> tags(TaskTagForTagsRequest request) throws Exception {
        super.fixRequest("task_tag", "tags", request);
        List<TaskTagForTagsResponse> list = super.tags(request);
        checkResult("task_tag", "tags", request, list);
        return list;
    }

    @Override
    public Integer countForTags(TaskTagForTagsRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_tag", "count_for_tags", request);
        return super.countForTags(request);
    }

    @Override
    public BaseStatResponse statForTags(TaskTagForTagsRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_tag", "stat_for_tags", request);
        return super.statForTags(request);
    }

}
